package com.zycx.common.entity;

import java.util.LinkedHashMap;

/**
 * Description: 驼峰工具类
 * Created by zycx on 2018-12-04 22:09
 * Created with IntelliJ IDEA.
 */
public class CamelMap extends LinkedHashMap {

    @Override
    public Object put(Object key, Object value) {
        key = camelMap(String.valueOf(key));
        return super.put(key, value);
    }

    public String camelMap(String inputString) {
        if (!inputString.contains("_")) {
            return inputString;
        }
        StringBuilder sb = new StringBuilder();

        boolean nextUpperCase = false;
        for (int i = 0; i < inputString.length(); i++) {
            char c = inputString.charAt(i);
            if (c == '_') {
                if (sb.length() > 0) {
                    nextUpperCase = true;
                }
            } else {
                if (nextUpperCase) {
                    sb.append(Character.toUpperCase(c));
                    nextUpperCase = false;
                } else {
                    sb.append(Character.toLowerCase(c));
                }
            }
        }
        return sb.toString();
    }

}
